import request from '#/utils/requestAbort';
import _ from 'lodash';
import { HttpCode } from '#/utils/contacts.js';

export const queryProvinceList = (menuCode) => {
  return request('/generation-common/correlaNodeStationConfig/queryProvinceList', {
    method: 'POST',
    data: { menuCode },
  });
};

/**
 * 数据权限，特殊处理：仅过滤出甘肃
 * @param {string} menuCode
 */
export const getGansuStations = async (menuCode) => {
  let error = ''; // 异常信息
  let stations = []; // 交易单元列表
  const provinceId = '62'; // 甘肃
  const res = await queryProvinceList(menuCode);
  if (res?.statusCode !== HttpCode.SUCCESS) {
    error = res?.message || '系统异常';
  }
  const power = res?.data || [];
  const gansuData = power.find((x) => x.value === provinceId)?.children || [];
  stations = _.flatten(gansuData.map((x) => x.children));
  return Promise.resolve({
    error,
    stations,
  });
};
